﻿	package app.demo.MyTouchApp{
	import flash.events.TUIO; // allows to connect to touchlib/tbeta
 
    import flash.display.*;
    import flash.events.*;
	import flash.events.MouseEvent;
    import flash.geom.*; // needed for curPt;
	import flash.display.SimpleButton;
	import flash.net.URLRequest;
	import flash.display.FrameLabel;
	import fl.controls.Label;
	import fl.controls.*;
	import fl.core.*;
	//import mx.controls.Label;
	import flash.display.Sprite;
	import flash.text.*;
	import flash.system.fscommand;
	import flash.system.*;
	
	public class selectBoard extends MovieClip {
		private var blobs:Array = new Array(); // blobs we are currently interacting with
        private var lines:Array = new Array(); // array to hold the lines
		
		private var images:Array = ["fruits.png", "letters.png", "numbers.png", "shape.png","white.jpg"];
		var image0:Loader = new Loader();
		var image1:Loader = new Loader();
		var image2:Loader = new Loader();
		var image3:Loader = new Loader();
		var image4:Loader = new Loader();
		
		public var button:SimpleButton;
		public var Exit:SimpleButton;
		private var numButtonWidth:Number = 100;
		private var numButtonHeight:Number = 50;
		
		
		var Label1:Label = new Label();
		
		var movie0:MovieClip = new MovieClip();
		var movie1:MovieClip = new MovieClip();
		var movie2:MovieClip = new MovieClip();
		var movie3:MovieClip = new MovieClip();
		var movie4:MovieClip = new MovieClip();
		var movie5:MovieClip = new MovieClip();
		var movie6:MovieClip = new MovieClip();
		
		//////
		private var imagesArray:Array = ["darkBackground.png", "shapesinahole.png", "chooseBoard.png"];
		var imageBackground:Loader = new Loader();
		public var buttonBack:Button;
		public var buttonExit:Button;
		var topicLabel:Label = new Label();
		var chooseLabel:Label = new Label();
		//////
		
		var myMaster:master;
		var topic:Loader = new Loader();
		var choose:Loader = new Loader();
		
		public function selectBoard(m:master):void {
			
			//fscommand("allowscale", "false");
			//fscommand("fullscreen", "false");
			//Stage.showMenu = false;
			
			myMaster=m;
			//--------connect to TUIO-----------------
			TUIO.init(this,'localhost',3000,'',true);
            trace("MyPage Initialized");
			
			addChild(movie1);
			
			
			//addEventListener(TouchEvent.MOUSE_DOWN, downEvent, false, 0, true); // run when finger down
            //addEventListener(TouchEvent.MOUSE_UP, upEvent, false, 0, true); // run when finger up
            //addEventListener(Event.ENTER_FRAME, updater, false, 0, true); // keep running
			
			//////////////////
			//Background:
			imageBackground.load(new URLRequest(imagesArray[0]));
			imageBackground.scaleX=1.4;
			movie1.addChild(imageBackground);
			
			//Back Button:
			buttonBack = new Button();
			buttonBack.label="BACK";
			buttonBack.width=100;
			buttonBack.height=40;
			//buttonBack.emphasized=true;
			buttonBack.addEventListener(TouchEvent.MOUSE_DOWN,backMethod);
			movie1.addChild(buttonBack);
			
			//Exit button:
			buttonExit = new Button;
			buttonExit.x=900;
			buttonExit.y=650;
			buttonExit.width=100;
			buttonExit.height=40;
			buttonExit.label="EXIT";
			buttonExit.addEventListener(TouchEvent.MOUSE_DOWN,closeApp);
			movie1.addChild(buttonExit);
			
			//Label (Choose Your character):
			var myTextFormat2:TextFormat = new TextFormat();
			myTextFormat2.font = "Kristen ITC";
			myTextFormat2.size = 30;
			
			chooseLabel.text = "Choose Topic:";
			chooseLabel.width= 600;
			chooseLabel.height= 300;
			chooseLabel.x=60;
			chooseLabel.y=130;
			chooseLabel.visible=true;
			chooseLabel.setStyle("textFormat", myTextFormat2);
			//movie1.addChild(chooseLabel);
			
			choose.load(new URLRequest(imagesArray[2]));
			choose.x=15;
			choose.y=120;
			//choose.scaleX=1.1;
			//choose.scaleY=1.1;
			movie1.addChild(choose);
				
			////////////////////////////
			
			
			image0.load(new URLRequest(images[4]));
			image0.x=0;
			image0.y=40;
			image0.scaleX=3;
			image0.scaleY=3;
			movie1.addChild(image0);
			//start();
			button = new SimpleButton;
			Exit= new SimpleButton;
			
			image1.load(new URLRequest(images[0]));
			image1.x=550;
			image1.y=450;
			//image1.scaleX=0.8;
			//image1.scaleY=0.8;
			
			image2.load(new URLRequest(images[1]));
			image2.x=550;
			image2.y=300; //195
			//image2.scaleX=0.8;
			//image2.scaleY=0.8;
			
			image3.load(new URLRequest(images[2]));
			image3.x=200;
			image3.y=450;
			//image3.scaleX=0.8;
			//image3.scaleY=0.8;
			
			image4.load(new URLRequest(images[3]));
			
			image4.x=200;
			image4.y=300; //195
			//image4.scaleX=0.8;
			//image4.scaleY=0.8;
			
			image1.addEventListener(TouchEvent.MOUSE_DOWN,natureMethod);
			image2.addEventListener(TouchEvent.MOUSE_DOWN,clothesMethod);
			image3.addEventListener(TouchEvent.MOUSE_DOWN,animalsMethod);
			image4.addEventListener(TouchEvent.MOUSE_DOWN,transportMethod);
			
			//movie1.addChild(image1);
			movie1.addChild(image2);
			//movie1.addChild(image3);
			movie1.addChild(image4);
			
			//Page Title (TOPIC MATCHING):
			var myTextFormat1:TextFormat = new TextFormat();
			myTextFormat1.font = "Kristen ITC";
			myTextFormat1.size = 70;
			
			topicLabel.text = "Topic Matching";
			topicLabel.width= 600;
			topicLabel.height= 300;
			topicLabel.x=260;
			topicLabel.visible=true;
			topicLabel.setStyle("textFormat", myTextFormat1);
			//movie1.addChild(topicLabel);
			
			topic.load(new URLRequest(imagesArray[1]));
			topic.x=240;
			topic.scaleX=1.1;
			topic.scaleY=1.1;
			movie1.addChild(topic);
			
			
			button.x=70;
			button.y=70;
			
			Exit.x=70;
			Exit.y=70;
			
			button.addEventListener(TouchEvent.MOUSE_DOWN,buttonDown);
			Exit.addEventListener(TouchEvent.MOUSE_DOWN,ExitDown);
			
			/*button.upState = drawButtonState(0xDAD8F3);
			button.overState = drawButtonState(0x4F42C6);
			button.downState = drawButtonState(0xDDF2FF);
			button.hitTestState = drawButtonState(0xDDF2FF);
			button.useHandCursor = true;
			
			Exit.upState = drawButtonState(0xDAD8F3);
			Exit.overState = drawButtonState(0x4F42C6);
			Exit.downState = drawButtonState(0xDDF2FF);
			Exit.hitTestState = drawButtonState(0xDDF2FF);
			Exit.useHandCursor = true;*/
			
			movie1.addChild(button);
			movie1.addChild(Exit);

		}
		
		
		function closeApp(event:TouchEvent):void
		{
     		 fscommand("quit");    
     	}
		
		private function backMethod(e:TouchEvent):void
		{
			myMaster.goBackToKeyboard();
		}
		
		private function exitMethod(e:TouchEvent):void
		{
			myMaster.goToWellDone();
		}
		private function buttonDown(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//button.alpha=0.5;
			removeChild(movie1);
			addChild(movie0); // the Page before that one
			
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
		}
		
		private function ExitDown(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//button.alpha=0.5;
			removeChild(movie1);
			//MyTouchApp.exit();
			addChild(movie2);
			
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
		}
		private function natureMethod(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//image1.alpha=0.5;
			//removeChild(movie1);
			//addChild(movie3);
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
		}
		
		private function animalsMethod(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//image1.alpha=0.5;
			//removeChild(movie1);
			//addChild(movie4);
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
		}
		
		private function clothesMethod(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//image1.alpha=0.5;
			//removeChild(movie1);
		//	addChild(movie5);
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
			myMaster.goToBoard3();
		}
		
		private function transportMethod(e:TouchEvent):void{
		// var curPt:Point=parent.globalToLocal(new Point(e.stageX,e.stageY));
          //  addBlob(e.ID, curPt.x, curPt.y);
            //e.stopPropagation();
			//image1.alpha=0.5;
			//removeChild(movie1);
			//addChild(movie6);
			myMaster.goToBoard();
			//button.upState = drawButtonState(0x4F42C6);
			//button.upState = drawButtonState(0x4F42C6);
		}
		
		
	}
	}